import axios_ from "@/utils/request";

export function listUser(query) {
    return axios_({
        url: '/api/sysUser/listByConditionLambda',
        method: 'get',
        params: query
    })
}

export function getInfo(id) {
    return axios_({
        url: `/api/sysUser/${id}`,
        method: 'get',
    })
}

export function saveUser(data) {
    return axios_({
        url: '/api/sysUser/save',
        method: 'post',
        data: data
    })
}

export function updateUser(data) {
    return axios_({
        url: '/api/sysUser/update',
        method: 'put',
        data: data
    })
}

export function deleteUser(id) {
    return axios_({
        url: `/api/sysUser/${id}`,
        method: 'delete',
    })
}

export function uploadAvatar(data) {
    return axios_({
        url: '/api/sysUser/uploadAvatar',
        method: 'post',
        data: data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 分表相关API
export function listShardingUser(query) {
    // 添加使用分表标志
    query.useSharding = true;
    
    return axios_({
        url: '/api/sysUser/list',
        method: 'get',
        params: query
    })
}

// 获取分表状态
export function getShardingStatus() {
    return axios_({
        url: '/api/sysUser/shardingStatus',
        method: 'get'
    })
}

// 设置分表状态
export function setShardingEnable(enable) {
    return axios_({
        url: '/api/sysUser/setShardingEnable',
        method: 'post',
        params: { enable }
    })
}

// 检查分表是否创建
export function checkShardingTables() {
    return axios_({
        url: '/api/migration/checkTables',
        method: 'get'
    })
}

// 获取分表统计信息
export function getShardingStats() {
    return axios_({
        url: '/api/migration/stats',
        method: 'get'
    })
}

// 启动数据迁移
export function migrateData(batchSize = 1000) {
    return axios_({
        url: '/api/migration/users',
        method: 'post',
        params: { batchSize }
    })
}

// 验证数据迁移一致性
export function validateMigration() {
    return axios_({
        url: '/api/migration/validate',
        method: 'get'
    })
}
